class Solution
{
public:
    int minTimeToType(string word)
    {
        char last = 'a';
        int time = 0;
        for (char c : word)
        {
            int diff = abs(c - last);
            time += min(diff, 26 - diff);
            last = c;
        }
        time += word.size();
        return time;
    }
};